<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace AlibabaCloud\Client\Request;

class RoaRequest extends Request
{
    use Traits\DeprecatedRoaTrait;
    public $pathPattern = "/";
    public $pathParameters = [];
    private $dateTimeFormat = "D, d M Y H:i:s \\G\\M\\T";
    public function resolveParameter()
    {
        $this->resolveQuery();
        $this->resolveHeaders();
        $this->resolveBody();
        $this->resolveUri();
        $this->resolveSignature();
    }
    private function resolveQuery()
    {
        if(!isset($this->options["query"]["Version"])) {
            $this->options["query"]["Version"] = $this->version;
        }
    }
    private function resolveBody()
    {
        if(isset($this->options["body"])) {
            return NULL;
        }
        if(!isset($this->options["form_params"])) {
            return NULL;
        }
        $params = \AlibabaCloud\Client\Support\Arrays::merge([$this->data, $this->options["form_params"]]);
        $this->encodeBody($params);
        unset($this->options["form_params"]);
    }
    private function encodeBody(array $params)
    {
        $stringy = \Stringy\Stringy::create($this->options["headers"]["Content-Type"]);
        if($stringy->contains("application/json", false)) {
            $this->options["body"] = json_encode($params);
            $this->options["headers"]["Content-MD5"] = base64_encode(md5($this->options["body"], true));
        } else {
            $this->options["body"] = \AlibabaCloud\Client\Encode::create($params)->ksort()->toString();
            $this->options["headers"]["Content-MD5"] = base64_encode(md5($this->options["body"], true));
            $this->options["headers"]["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
        }
    }
    private function resolveHeaders()
    {
        $this->options["headers"]["x-acs-version"] = $this->version;
        $this->options["headers"]["x-acs-region-id"] = $this->realRegionId();
        $this->options["headers"]["Date"] = gmdate($this->dateTimeFormat);
        $signature = $this->httpClient()->getSignature();
        $this->options["headers"]["x-acs-signature-method"] = $signature->getMethod();
        $this->options["headers"]["x-acs-signature-nonce"] = \AlibabaCloud\Client\Support\Sign::uuid($this->product . $this->realRegionId());
        $this->options["headers"]["x-acs-signature-version"] = $signature->getVersion();
        if($signature->getType()) {
            $this->options["headers"]["x-acs-signature-type"] = $signature->getType();
        }
        $this->resolveAccept();
        $this->resolveContentType();
        $this->resolveSecurityToken();
        $this->resolveBearerToken();
    }
    private function resolveSignature()
    {
        $this->options["headers"]["Authorization"] = $this->signature();
    }
    private function resolveAccept()
    {
        if(!isset($this->options["headers"]["Accept"])) {
            $this->options["headers"]["Accept"] = \AlibabaCloud\Client\Accept::create($this->format)->toString();
        }
    }
    private function resolveContentType()
    {
        if(!isset($this->options["headers"]["Content-Type"])) {
            $this->options["headers"]["Content-Type"] = $this->options["headers"]["Accept"] . "; charset=utf-8";
        }
    }
    private function resolveSecurityToken()
    {
        if(!$this->credential() instanceof \AlibabaCloud\Client\Credentials\StsCredential) {
            return NULL;
        }
        if(!$this->credential()->getSecurityToken()) {
            return NULL;
        }
        $this->options["headers"]["x-acs-security-token"] = $this->credential()->getSecurityToken();
    }
    private function resolveBearerToken()
    {
        if($this->credential() instanceof \AlibabaCloud\Client\Credentials\BearerTokenCredential) {
            $this->options["headers"]["x-acs-bearer-token"] = $this->credential()->getBearerToken();
        }
    }
    private function signature()
    {
        $credential = $this->credential();
        $access_key_id = $credential->getAccessKeyId();
        $signature = $this->httpClient()->getSignature()->sign($this->stringToSign(), $credential->getAccessKeySecret());
        return "acs " . $access_key_id . ":" . $signature;
    }
    private function resolveUri()
    {
        $path = \AlibabaCloud\Client\Support\Path::assign($this->pathPattern, $this->pathParameters);
        $this->uri = $this->uri->withPath($path)->withQuery($this->queryString());
    }
    public function stringToSign()
    {
        $request = new \GuzzleHttp\Psr7\Request($this->method, $this->uri, $this->options["headers"]);
        return \AlibabaCloud\Client\Support\Sign::roaString($request);
    }
    private function queryString()
    {
        $query = isset($this->options["query"]) ? $this->options["query"] : [];
        return \AlibabaCloud\Client\Encode::create($query)->ksort()->toString();
    }
    public function pathParameter($name, $value)
    {
        \AlibabaCloud\Client\Filter\Filter::name($name);
        if($value === "") {
            throw new \AlibabaCloud\Client\Exception\ClientException("Value cannot be empty", \AlibabaCloud\Client\SDK::INVALID_ARGUMENT);
        }
        $this->pathParameters[$name] = $value;
        return $this;
    }
    public function pathPattern($pattern)
    {
        \AlibabaCloud\Client\Filter\ApiFilter::pattern($pattern);
        $this->pathPattern = $pattern;
        return $this;
    }
    public function __call($name, $arguments)
    {
        if(strncmp($name, "get", 3) === 0) {
            $parameter_name = mb_strcut($name, 3);
            return $this->__get($parameter_name);
        }
        if(strncmp($name, "with", 4) === 0) {
            $parameter_name = mb_strcut($name, 4);
            $this->__set($parameter_name, $arguments[0]);
            $this->pathParameters[$parameter_name] = $arguments[0];
            return $this;
        }
        if(strncmp($name, "set", 3) === 0) {
            $parameter_name = mb_strcut($name, 3);
            $with_method = "with" . $parameter_name;
            throw new \RuntimeException("Please use " . $with_method . " instead of " . $name);
        }
        throw new \RuntimeException("Call to undefined method AlibabaCloud\\Client\\Request\\RoaRequest::" . $name . "()");
    }
}

?>